package ch.ethz.fcl.metrobuzz.render.techniques.colors;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;

import ch.ethz.fcl.metrobuzz.controller.MBController;
import ch.ethz.fcl.metrobuzz.tools.MBGL;
import ch.ethz.fcl.metrobuzz.viewer.MBViewer;

public class MBColorTest {
	MBColor color;
	private MBViewer view;
	private MBController control;

	public static void main(String[] args) {
		new MBColorTest().run();
	}

	public MBColorTest() {
		init();
	}

	public void run() {
		while (true) {
			try {
				Thread.sleep(20);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

			GL11.glPushMatrix();
			view.update();
			MBGL.enableBlend();
			if (MBViewer.newUpdate) {
				render();

				Display.update();
			}
			control.update();
			GL11.glPopMatrix();
		}
	}

	private void init() {
		view = new MBViewer(MBViewer.ProjectionType.Perspective);

		control = new MBController(view);

		color = new MBColor(0, 1, 1);
	}

	private void render() {
		// MBColor cc = color.transformHSV(0, 1, 1);
		GL11.glLineWidth(3.0f);
		GL11.glPointSize(10.0F);
		GL11.glBegin(GL11.GL_POINTS);

		for (int i = 0; i <= MBColorTable.COLORS; i++) {
			for (int j = 0; j < 10; j++) {
				MBColorTable.assignColor((i + 1) * 10 + j, 1.0f);
				GL11.glVertex3f(0.1f * i, 0.1f * j, 0);
			}

			MBColorTable.assignColor(i, 1.0f);
			GL11.glVertex3f(0.1f * i, -0.1f, 0);
		}
		GL11.glEnd();

		MBViewer.newUpdate = false;
	}
}
